<!DOCTYPE html>
<html>
	<head>
		<script type="text/javascript" src="jquery-3.6.0.js"></script>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			div{
				margin-left: 5rem ;
			}
		</style>
	</head>
	<body>
		<form action="#">
			第一个数：<input type="text" id="one"><br>
			第二个数：<input type="text" id="two">
			<div>
				<input type="button" value="+" id="add">
				<input type="button" value="-" id="sub">
				<input type="button" value="*" id="mul">
				<input type="button" value="/" id="divi">
			</div>
			计算结果：<input type="text" id="three">
		</form>
		<script type="text/javascript">
			for(var i=0; i<4;i++){
				$("input[type=button]").eq(i).bind("click",fun);
			}
			function fun(event){
				var otarget;
				if(window.event){
					event = window.event
					otarget = event.srcElement
				}else{
					otarget = event.target
				}
				var str1 = document.getElementById("one").value
				var str2 = document.getElementById("two").value
				var result = document.getElementById("three");
				var numx = Math.pow(10,Math.max(str1.length - str1.indexOf("."),str2.length - str2.indexOf("."))) 
				if(otarget.value == "*"|| otarget.value == "/"){
					result.value = (eval(str1 * numx + otarget.value + str2 * numx))/(eval( numx + otarget.value + numx));
				}else{
					result.value = (eval(str1 * numx + otarget.value + str2 * numx))/numx;
				}
			}
		</script>
	</body>
</html>
